/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.radeox;

import foo.bar.blog.core.domain.*;
import foo.bar.radeox.api.engine.RenderEngine;
import foo.bar.radeox.engine.context.BaseRenderContext;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.LinkedHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Decorates a {@link Entry} object by providing {@link #getDecoratedContent()} which is a
 * {@link RenderEngine} decorated content of {@link foo.bar.blog.core.domain.Entry}'s content.
 *
 * @see {@link foo.bar.blog.radeox.DecoratedEntryTransformer}
 *
 * @author tmjee
 * @version $Date: 2009-07-05 10:12:59 +0000 (Sun, 05 Jul 2009) $ $Id$
 */
public class DecoratedEntry extends Entry implements EntryInterface, CreationInfoPersistable, ModificationInfoPersistable, Identifiable, Decoratable {

    private static final Log LOG = LogFactory.getLog(DecoratedEntry.class);


    private RenderEngine renderEngine;
    private Entry entry;

    public DecoratedEntry(RenderEngine renderEngine, Entry entry) {
        this.renderEngine = renderEngine;
        this.entry = entry;
    }

    public Blog getBlog() {
        return entry.getBlog();
    }

    public void setBlog(Blog blog) {
        entry.setBlog(blog);
    }

    public void setTag(Tag tag) {
        entry.setTag(tag);
    }

    public Tag getTag() {
        return entry.getTag();
    }

    public Set getComments() {
        if (entry.getComments() != null) {
            Set<DecoratedComment> result = new LinkedHashSet<DecoratedComment>();
            for (Comment comment: entry.getComments()) {
                result.add(new DecoratedComment(renderEngine, comment));
            }
            return result;
        }
        return entry.getComments();
    }

    public void setComments(Set<Comment> comments) {
        entry.setComments(comments);
    }

    public String getName() {
        return entry.getName();
    }

    public void setName(String name) {
        entry.setName(name);
    }

    public String getDescription() {
        return entry.getDescription();
    }

    public void setDescription(String description) {
        entry.setDescription(description);
    }

    public String getContent() {
        return entry.getContent();
    }

    public void setContent(String content) {
        entry.setContent(content);
    }

    public Date getPublishDate() {
        return entry.getPublishDate();
    }

    public void setPublishDate(Date publishDate) {
        entry.setPublishDate(publishDate);
    }

    public EntryState getState() {
        return entry.getState();
    }

    public void setState(EntryState state) {
        entry.setState(state);
    }

    public long getTotalComments() {
        return entry.getTotalComments();
    }

    public void setCreationDate(Date creationDate) {
        entry.setCreationDate(creationDate);
    }

    public Date getCreationDate() {
        return entry.getCreationDate();
    }

    public void setCreator(User creator) {
        entry.setCreator(creator);
    }

    public User getCreator() {
        return entry.getCreator();
    }

    public void setModificationDate(Date modificationDate) {
        entry.setModificationDate(modificationDate);
    }

    public Date getModificationDate() {
        return entry.getModificationDate();
    }

    public void setModifier(User modifier) {
        entry.setModifier(modifier);
    }

    public User getModifier() {
        return entry.getModifier();
    }

    public long getId() {
        return entry.getId();
    }


    public String getDecoratedContent() {
        BaseRenderContext context = new BaseRenderContext();
        context.setParameters(new LinkedHashMap(){
            {
                put(BlogRenderEngine.RENDER_CONTEXT_ENTRY_ID_PARAM_KEY, entry.getId());
            }
        });
        return renderEngine.render(getContent(), context);
    }
}
